package com.example.fragmentTest2;

import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.FrameLayout;
import android.os.Build;

public class MainActivity extends Activity implements OnItemSelectedListener{

	TitleListFragment list;
	FrameLayout layout;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		list = new TitleListFragment();
		
		getFragmentManager().beginTransaction().add(R.id.listFragment, list).commit();
		
		layout = (FrameLayout) findViewById(R.id.listFragment);
		layout.setVisibility(View.INVISIBLE);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.main, menu);
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		if(item.getItemId() == R.id.action_settings){
			if(layout.getVisibility() == View.INVISIBLE){
				layout.setVisibility(View.VISIBLE);
				layout.setAnimation(AnimationUtils.loadAnimation(this, R.anim.left_start));
			}else{
				layout.setAnimation(AnimationUtils.loadAnimation(this, R.anim.right_start));
				layout.setVisibility(View.INVISIBLE);
			}
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
			long arg3) {
		// TODO Auto-generated method stub
		layout.setAnimation(AnimationUtils.loadAnimation(this, R.anim.right_start));
		layout.setVisibility(View.INVISIBLE);
	}

	@Override
	public void onNothingSelected(AdapterView<?> arg0) {
		// TODO Auto-generated method stub
		
	}

}
